layui.use(['table', 'form', 'laydate', 'laytpl', 'element'], function() {
	var table = layui.table;
	form = layui.form,
		$ = layui.jquery,
		laydate = layui.laydate,
		laytpl = layui.laytpl,
		element = layui.element;

	/*动态加载测试报告类型下拉框*/
	$.ajax({
		type: 'get',
		url: '../json/testReportType.json',
		datatype: 'json',
		success: function(typedate) {
			if(typedate.code == 0) {
				var str = "";
				for(var i = 0; i < typedate.count; i++) {
					str += '<option value=' + typedate.data[i].name + '>' + typedate.data[i].name + '</option>';
				}
				$("#checkType").append(str);
				form.render("select");
			} else {
				layer.msg("测试报告类型获取失败");
			}
		}
	});

	form.on('select(selgradename)', function(data) {
		var grade = data.value;
		var schoolid = $("#selschool").val();
		if(schoolid == 00) {
			schoolid = "";
		}
		/*动态加载班级下拉框*/
		$("#classid").html("");
		$.ajax({
			type: 'get',
			url: '../sysclassmanagement/getclassbygrade?grade=' + grade + '&schoolid=' + schoolid,
			datatype: 'json',
			success: function(classdate) {
				if(classdate.code == 0) {
					var str = "<option value='00'>请选择班级</option>";
					for(var i = 0; i < classdate.count; i++) {
						str += '<option value=' + classdate.data[i].classid + '>' + classdate.data[i].className + '</option>';
					}
					$("#classid").append(str);
					form.render("select");
				} else {
					$("#classid").html("");
					layer.msg('暂无对应的班级', {
						icon: 2
					});
					form.render("select");
				}
			}
		});
	});

	table.render({
		elem: '#tabclasseva',
		url: '../sysclassevalresultdetails/getclassevaresult',
		title: '班级测评结果详细表',
		height: "full-110",
		skin: 'line',
		even: true,
		cols: [
			[{
				title: '序号',
				type: 'numbers',
				align: 'center',
				width: '8%'
			}, {
				field: 'totalclassname',
				title: '班级',
				align: 'center',
				width: '25%'
			}, {
				field: 'checkname',
				title: '测评报告类型',
				align: 'center',
				width: '35%'
			}, {
				field: 'checktime',
				title: '测评时间',
				align: 'center',
				width: '18%'
			}, {
				title: '操作',
				toolbar: '#barDemo',
				align: 'center',
				width: '14%'
			}]
		],
		page: {
			layout: ['prev', 'page', 'next', 'skip', 'count', 'limit'],
			groups: 5,
			limit: 10,
			limits: [10, 20, 30, 40, 50],
			theme: '#1E9FFF',
		}
	});

	//点击查询按钮
	$("#btnseleva").click(function() {
		var reporttype = $("#checkType").val();
		var schoolid = $("#selschool").val();
		var grade = $("#selgradename").val();
		var classid = $("#classid").val();
		if(reporttype == 00) {
			reporttype = "";
		}
		if(schoolid == 00) {
			schoolid = "";
		}
		if(grade == 00) {
			grade = "";
		}
		if(classid == 00) {
			classid = "";
		}
		table.render({
			elem: '#tabclasseva',
			url: '../sysclassevalresultdetails/getclassevaresult?reporttype=' + reporttype + "&grade=" + grade + "&classid=" + classid + "&schoolid=" + schoolid,
			title: '班级测评结果详细表',
			height: "full-110",
			skin: 'line',
			even: true,
			cols: [
				[{
					title: '序号',
					type: 'numbers',
					align: 'center',
					width: '8%'
				}, {
					field: 'totalclassname',
					title: '班级',
					align: 'center',
					width: '25%'
				}, {
					field: 'checkname',
					title: '测评报告类型',
					align: 'center',
					width: '35%'
				}, {
					field: 'checktime',
					title: '测评时间',
					align: 'center',
					width: '18%'
				}, {
					title: '操作',
					toolbar: '#barDemo',
					align: 'center',
					width: '14%'
				}]
			],
			page: {
				layout: ['prev', 'page', 'next', 'skip', 'count', 'limit'],
				groups: 5,
				limit: 10,
				limits: [10, 20, 30, 40, 50],
				theme: '#1E9FFF',
			}
		});
	});

	//点击班级结果测评查看
	table.on('tool(tabclasseva)', function(obj) {
		var classdata = obj.data;
		if(obj.event === 'btnselclassdetail') {
			var classevaresult = classdata.checkname;
			if(classevaresult.indexOf("EPQ") >= 0) {
				var para = "checktypeid=" + classdata.checktypeid;
				para += "&checktime=" + classdata.checktime;
				para += "&classid=" + classdata.classid;
				para += "&schoolname=" + classdata.schoolName;
				para += "&totalclassname=" + classdata.totalclassname;
				var index = layer.open({
					type: 2,
					title: '班级(EPQ)的测试报告结果详细',
					area: ['830px', '95%'],
					shade: 0.8,
					maxmin: true,
					content: ['../classEvalResultManagement/ClassEPQCheckReport.jsp?' + para, 'yes'],
					cancel: function() {}
				});
				layer.full(index);
			} else if(classevaresult.indexOf("MHT") >= 0) {
				var para = "checktypeid=" + classdata.checktypeid;
				para += "&checktime=" + classdata.checktime;
				para += "&classid=" + classdata.classid;
				para += "&schoolname=" + classdata.schoolName;
				para += "&totalclassname=" + classdata.totalclassname;
				var index = layer.open({
					type: 2,
					title: '班级(MHT)的测试报告结果详细',
					area: ['830px', '95%'],
					shade: 0.8,
					maxmin: true,
					content: ['../classEvalResultManagement/ClassMHTCheckReport.jsp?' + para, 'yes'],
					cancel: function() {}
				});
				layer.full(index);
			}
		}
	});
});